package com.qf.service;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.entity.dto.City;
import com.qf.mapper.CityMapper;
import com.qf.service.redis.RedisService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CityService extends ServiceImpl<CityMapper,City> {

    @Resource
    private RedisService redisService;

    @Transactional
    public List<City> queryCity(String provinceId) {
        List<City> list2 = null;
        String city = (String)redisService.hget("city",provinceId);
        if (city != null && !city.equals("")) {
            list2 = JSONObject.parseArray(city, City.class);
            return list2;
        }
        list2 = this.baseMapper.queryCity(provinceId);
        String s = JSONObject.toJSONString(list2);
        redisService.hset("city",provinceId, s);
        return list2;
    }
}
